﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace AAA.Base.Util.Graphic
{
    public class FontUtil
    {
        private const int MIN_FONT_SIZE = 5;
        private const int MAX_FONT_SIZE = 25;

        public static Font CreateFont(Graphics g, string strFontFamily, FontStyle fontStyle, string strText, int iHeightLimit, int iWidthLimit)
        {
            Font font = null;            
            SizeF size;

            try
            {
                for(int i = MIN_FONT_SIZE; i < MAX_FONT_SIZE; i++)
                {
                    font = new Font(strFontFamily, i, fontStyle);
                    size = g.MeasureString(strText, font);
                    if ((size.Width > iWidthLimit) || (size.Height > iHeightLimit))
                        return font;
                }
            }
            catch(Exception ex)
            {
                throw ex;
            }
            return font;
        }

    }
}
